<template>
  <div>
    <router-link tag="div" to="/" class="header-abs" v-show="!ShowHeader">
      <i class="iconfont">&#xe624;</i>
    </router-link>
    <div class="header-title" :style="opacityStyle" v-show="ShowHeader">
      <i>城市选择</i>
      <router-link to="/">
        <i class="iconfont backIcon">&#xe624;</i>
      </router-link>
    </div>
  </div>
</template>

<script>
export default {
  name: 'DetailHeader',
  data () {
    return {
      ShowHeader: false,
      opacityStyle: {
        opacity: 0
      }
    }
  },
  methods: {
    handleScroll () {
      const scrollTop = document.documentElement.scrollTop
      if (scrollTop > 50) {
        const opacity = scrollTop / 140
        this.ShowHeader = true
        this.opacityStyle = {opacity}
      } else {
        this.ShowHeader = false
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handleScroll)
  },
  deactivated () {
    window.removeEventListener('scroll', this.handleScroll)
  }
}
</script>

<style lang="stylus" scoped>
  @import "~_styles/varibles.styl"
  .header-abs
    position: absolute
    left: .2rem
    top: .2rem
    width: .8rem
    height: .8rem
    line-height: .8rem
    text-align: center
    border-radius: .4rem
    background-color: rgba(0, 0 , 0, .7)
    color: #fff
  .header-title
    position: fixed
    top: 0
    right: 0
    left: 0
    height: $headerHeight
    line-height: $headerHeight
    background-color: $bgColor
    text-align: center
    font-size: .28rem
    color: #fff
    .backIcon
      position: absolute
      left: 0
      top: 0
      width: .86rem
      height: .86rem
      color: #fff
</style>
